<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class FileMeta extends CMiniyunModel
{

    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return Yii::app()->params['tablePrefix'].'file_metas';
    }
    
    public function deleteFileMeta($userIds){
        if($userIds!='' && strlen($userIds)>0){
            $idsArray = explode(",",$userIds);
            foreach($idsArray as $index=>$userId){
                $this->deleteAll("file_path like '/".$userId."/%'");
            }
        }
    }
    
    public function deleteFileMetaByPath($idsArray){
        if(count($idsArray)>0){
            foreach($idsArray as $key=>$item){
                $this->deleteAll("file_path like '".$item."%'");
            }
        }
    }
    
    public function getFileBaseMate($ids){
        if($ids=="") return array();
        return $this->findAll(array('condition'=>"file_path in(".$ids.")"));
    }
    
    
    public function getFileMeta($filePath, $metaKey, $all = false) {
        if ($all) {
            return $this->findAll(array('condition' => 'file_path=:file_path and meta_key =:meta_key',
                                        'params'    => array(':file_path'=>$filePath, ':meta_key' => $metaKey)));
        } else {
            return $this->find(array('condition' => 'file_path=:file_path and meta_key =:meta_key',
                                     'params'    => array(':file_path'=>$filePath, ':meta_key' => $metaKey)));
        }
    }
}